package org.goj.management.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.goj.common.entity.management.News;
import org.goj.common.entity.user.Topic;
import org.goj.management.mapper.NewsMapper;
import org.goj.management.service.NewsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 新闻表 服务实现类
 * </p>
 *
 * @author CK
 * @since 2020-12-02
 */
@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements NewsService {

    @Resource
    private NewsMapper newsMapper;

    @Override
    public Page<News> listNews() {
        QueryWrapper<News> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 0).orderByDesc("time");
        Page<News> page = new Page<>(1, 5);
        return newsMapper.pageNews(page, queryWrapper);
    }

    @Override
    public List<News> adminListNews(Integer newsId) {
        QueryWrapper<News> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("status").orderByDesc("time")
                .eq(newsId != -1, "news_id", newsId);
        return super.list(queryWrapper);
    }
}
